package com.yidu.hbatsft.service.impl;

import com.github.pagehelper.PageHelper;
import com.yidu.hbatsft.dao.AtsRivalMapper;
import com.yidu.hbatsft.domain.AtsRival;
import com.yidu.hbatsft.service.RivalSerice;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class RivalSericeimpl implements RivalSerice {

    @Resource
    AtsRivalMapper atsRivalMapper;

    @Override
    public int deleteByPrimaryKey(Integer rivId) {
        return 0;
    }


    @Override
    public int insertSelective(AtsRival record) {
        return 0;
    }

    @Override
    public AtsRival selectByPrimaryKey(Integer rivId) {

        AtsRival as = new AtsRival();
        as = atsRivalMapper.selectByPrimaryKey(rivId);
        return as;
    }

    @Override
    public int updateByPrimaryKeySelective(AtsRival record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(AtsRival record) {
        return 0;
    }

    @Override
    public void updates(int id) {

    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id) {
        atsRivalMapper.updates(id);


    }

    /***
     * 批量删除
     * @param ids
     */

    @Override
    public void deleteAll(String ids) {

        String temp[] = ids.split(",");
        for (int i = 0; i < temp.length; i++) {
            String id = temp[i];
            if (StringUtils.isEmpty(id)) {
                continue;
            }
            delete(Integer.valueOf(id));
        }

    }

    @Override
    public List<AtsRival> option(AtsRival atsRival) {


        List<AtsRival> list = atsRivalMapper.option(atsRival.getRivId());


        return list;
    }


    /**
     * 根据日期查询
     * @param
     * @return
     */
    @Override
    public List<AtsRival> selectAllt(String creatTime) {
        AtsRival as = new AtsRival();

        List<AtsRival> list = atsRivalMapper.selectAllt(as.getCreatTime());

        return null;
    }



    /**
     * 很据id查询
     * @param id
     * @return
     */
    @Override
    public AtsRival findbyid(Integer id) {


        AtsRival as  = atsRivalMapper.findbyid(id);
        return as;


    }




    @Override
    public List<AtsRival> selectAll(Map<String, Object> map) {

        return null;

    }

    @Override
    public List<AtsRival> findAll(Integer pageNum, Integer pageSize, String rivName ,String creatTimes,String creatTimea,int i,String id) {

        PageHelper.startPage(pageNum,pageSize);



        if(i==1){
            return atsRivalMapper.selectAlltc(id,rivName,creatTimes, creatTimea);
        }else if(i==2){
            return atsRivalMapper.findAll(rivName,creatTimes, creatTimea);
        }else{
            return null;
        }

    }

    /**
     * 新增
     * @param record
     * @return
     */
    @Override
    public int insert(AtsRival record){

        Date date = new Date();
        //:hh:mm:ss
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");



        record.setIsva(1);
        if (StringUtils.isEmpty(record.getRivId())) {

            record.setIsva(1);
            record.setCreater("admin");
            record.setCreatTime(dateFormat.format(date));
            return atsRivalMapper.insert(record);
        }else{

            record.setIsva(1);
            record.setCreater("admin");
            record.setCreatTime(dateFormat.format(date));
            return atsRivalMapper.updateByPrimaryKey(record);
        }
    }




    @Override
    public int count(String rivName) {


        return atsRivalMapper.count(rivName);
    }





}
